<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"   lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>岗位管理</title>
        <link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.5.4.5/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.5.4.5/themes/icon.css">
        <script src="/js/jquery-easyui-1.5.4.5/jquery.min.js"></script>
        <script src="/js/jquery-easyui-1.5.4.5/jquery.easyui.min.js"></script>
    </head>

    <body>
	    <table class="easyui-datagrid" title="岗位管理" style="width:90%;height:500px" id="table-grid"
			data-options="singleSelect:true,collapsible:false,url:'/baseControl/GET/cn.com.fig.dao.GroupMapper.listGroup',method:'get',toolbar:toolbar,pagination:true,pageSize:20">
		<thead>
			<tr>
				<th data-options="field:'groupId',width:200">岗位编号</th>
				<th data-options="field:'groupName',width:400">岗位名称</th>
				<th data-options="field:'groupDesc',width:400">岗位描述</th>
				<th data-options="field:'groupStatus',width:100,formatter: function(value,row,index){
				if(value == '0') return '无效';
				if(value == '1') return '有效';
			}">岗位状态</th>
			</tr>
		</thead>
	</table>
	<div id="saveWindows" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:300px;padding:10px;">
		<form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
			<table>
				<tr>
					<td width="80px">岗位编号:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="groupId" id="groupId" data-options="required:true" width='300px'></input>
	    			</td>
				</tr>
				<tr>
					<td>岗位名称:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="groupName" id="groupName" data-options="required:true" width="300px"></input>
	    			</td>
				</tr>
				<tr>
					<td>岗位描述:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="groupDesc" id="groupDesc" data-options="required:true" width="300px"></input>
	    			</td>
				</tr>
				<tr>
					<td>岗位状态:</td>
	    			<td>		    			
						<select id="groupStatus" class="easyui-combobox" name="groupStatus"  style="width:200px;">
						    <option value="1">有效</option>
						    <option value="0">无效</option>
						</select>
						<input id='insertMark' name='insertMark' type='hidden' value='0'>
					</td>
				</tr>
				<tr>
				<td><input type='button' onclick="submitForm();" value='保存'/></td>
				<td><input type='button' onclick="$('#saveWindows').window('close');" value='取消'/></td>
				</tr>
			</table>
		</form>
	</div>
	
  <script type="text/javascript">		
	//dataGrid工具栏
	var toolbar = [{
				text:'新增',
				iconCls:'icon-add',
				handler:function(){
					var tt = $('#table-grid');
					var node = tt.datagrid('getSelected');
					var pId = null;
					$('#insertMark').val('1');
					$("#saveWindows").window('open');
				}
			},{
				text:'编辑',
				iconCls:'icon-edit',
				handler:function(){
					var tt = $('#table-grid');
					var row=tt.datagrid('getSelected');
					if(row){
						$("#saveWindows").window('open');
						$('#insertMark').val('0');
						$('#groupId').textbox("setValue",row.groupId);
						$('#groupName').textbox("setValue",row.groupName);
						$('#groupDesc').textbox("setValue",row.groupDesc);
						$('#groupStatus').combobox("select",row.groupStatus);
						
					}else{
						$.messager.alert('Warning','请选择要编辑的行！');
					}
				}
			},{
				text:'删除',
				iconCls:'icon-remove',
				handler:function(){
							var tt = $('#table-grid');
							var row=tt.datagrid('getSelected');
							if(!row){
								$.messager.alert('Warning','请选择要删除的行！');
							}
					$.messager.confirm('提示','您确定要删除吗？',function (r){
						if(r){
							$.ajax({
								   type: "POST",
								   dataType:"json",
								   url: "/baseControl/DELETE/cn.com.fig.dao.GroupMapper.deleteGroup",
								   data: {priId:row.groupId},
								   success: function(msg){
								     if(msg){
								    	 $.messager.alert('Warning',msg.retMsg);
								    	 $('#table-grid').datagrid('reload');
								     }
								   }
								});
						}
					});
				}
			}];
	$(function(){
		$('#ff').form({
			url:"/baseControl/POST",
			onSubmit: function(){
				var isValid = $(this).form('validate');
				if (!isValid){
					$.messager.alert('Warning','请填写必填项');
				}
				return isValid;	
			},
			success:function(msg){
			     if(msg){
			    	 var data = eval('(' + msg + ')');
			    	 $.messager.alert('Warning',data.retMsg);
			    	 $('#table-grid').datagrid('reload');
			    	 $("#saveWindows").window('close');
			     }
			}
		});
	});
	
	function submitForm(){
		var insertMark = $('#insertMark').val();
		var reqUrl = ''
		if(insertMark == 0){
			reqUrl = '/baseControl/POST/cn.com.fig.dao.GroupMapper.updateGroup';
		}else{
			reqUrl = '/baseControl/PUT/cn.com.fig.dao.GroupMapper.insertGroup';
		}
		
		$('#ff').form("submit",{
			url:reqUrl
		});	
	}
	</script>      
    </body>
</html>
